<template>
  <el-dialog
    :title="{ add: '添加权限点', edit: '编辑权限点' }[mode]"
    :visible="isSHOW"
    @close="outDia"
  >
    <el-form ref="form" label-width="100px" :rules="rules" :model="form">
      <el-form-item label="权限名称" prop="name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="极限标识" prop="code">
        <el-input v-model="form.code" />
      </el-form-item>
      <el-form-item label="极限描述" prop="description">
        <el-input v-model="form.description" />
      </el-form-item>
      <el-form-item label="企业可见" prop="">
        <el-switch
          v-model="form.enVisible"
          active-text="可见"
          active-value="1"
          inactive-text="不可见"
          inactive-value="0"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="parm" @click="submit">确定</el-button>
      <el-button @click="outDia">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { sysPermissionAPIPOST, sysPermissionPUTAPI } from '@/api'
export default {
  model: {
    prop: 'isSHOW'
  },
  props: {
    isSHOW: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        enVisible: '0', // string	非必须  0 可见1不可见
        name: '', //	string	非必须
        code: '', //	string	非必须
        description: '', // string	非必须
        type: '', //	number	非必须     页面:1  按钮2
        pid: '' // string	非必须
      },
      rules: {
        name: [{ required: true, message: '必填', trigger: 'change' }],
        code: [{ required: true, message: '必填', trigger: 'change' }],
        description: [{ required: true, message: '必填', trigger: 'change' }]
      },
      mode: 'add'
    }
  },
  methods: {
    outDia() {
      this.$emit('input', false)
      this.$refs.form.resetFields()
      this.form = {
        enVisible: '0', // string	非必须  0 可见1不可见
        name: '', //	string	非必须
        code: '', //	string	非必须
        description: '', // string	非必须
        type: '', //	number	非必须     页面:1  按钮2
        pid: '' // string	非必须
      }
    },
    submit() {
      this.$refs.form.validate(async(result) => {
        if (result) {
          if (this.mode == 'add') {
            const res = await sysPermissionAPIPOST(this.form)
            console.log(res)
            this.$message.success('添加成功')
          } else if (this.mode == 'edit') {
            const res = await sysPermissionPUTAPI(this.form)
            this.$message.success('修改成功')
          }
          this.outDia()
          this.$emit('getDate')
        }
      })
    }
  }
}
</script>

<style></style>
